package org.amicofragile.test.springintegration.logic;

import java.text.MessageFormat;

import org.amicofragile.test.springintegration.dto.Person;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;

public class HelloServiceImpl implements HelloService
{
	private static final Log LOG = LogFactory.getLog(HelloServiceImpl.class.getName());

	@Autowired(required = true)
	private CalculusService calculusService;

	public void sayHelloTo(Person person)
	{
		if (LOG.isDebugEnabled())
		{
			final String message = MessageFormat.format("HelloServiceImpl.sayHelloTo({0})", person.toString());
			LOG.debug(message);
			if (LOG.isTraceEnabled())
			{
				LOG.trace(message);
			}
		}
		LOG.info("Hello, " + person.getName() + " " + person.getSurname() + "; " + this.calculusService.calculate(person.getName().length(), person.getSurname().length()));
	}

	@Override
	public Person normalize(Person person)
	{
		return new Person(person.getName().toUpperCase(), person.getSurname().toUpperCase());
	}
}
